introduce route_head::empty() (#1074)
authortsteven4 <13596209+tsteven4@users.noreply.github.com>
Fri, 21 Apr 2023 00:07:54 +0000 (18:07 -0600)
committerGitHub <noreply@github.com>
Fri, 21 Apr 2023 00:07:54 +0000 (18:07 -0600)
defs.h
garmin_txt.cc
gdb.cc
gtm.cc
humminbird.cc
kml.cc
osm.cc
ozi.cc
position.cc
trackfilter.cc

diff --git a/defs.h b/defs.h
index c4b68a2e0317947c9cb4893e055a951dd70b89d8..c255e5b766f0503e5db945d717149330c55b0e45 100644 (file)
--- a/defs.h
+++ b/defs.h
@@ -647,6 +647,7 @@ public:
   ~route_head();
 
   int rte_waypt_ct() const {return waypoint_list.count();}             /* # waypoints in waypoint list */
+  bool rte_waypt_empty() const {return waypoint_list.empty();}
 };
 
 using route_hdr = void (*)(const route_head*);
index ed5b19c3e36cf2e0c5b94ace5181fa64ee220776..24d7e4dd3184a1c8f2f8ae496c20873aead460d7 100644 (file)
@@ -614,7 +614,7 @@ route_disp_hdr_cb(const route_head* rte)
   cur_info = &route_info[route_idx];
   cur_info->prev_wpt = nullptr;
   cur_info->total = 0;
-  if (rte->rte_waypt_ct() <= 0) {
+  if (rte->rte_waypt_empty()) {
     return;
   }
 
@@ -668,7 +668,7 @@ track_disp_hdr_cb(const route_head* track)
   cur_info = &route_info[route_idx];
   cur_info->prev_wpt = nullptr;
   cur_info->total = 0;
-  if (track->rte_waypt_ct() <= 0) {
+  if (track->rte_waypt_empty()) {
     return;
   }
 
diff --git a/gdb.cc b/gdb.cc
index b42b536042294f877637330cf6f27d6ee3f356b1..7ba6bd6ca0fc0625dd8848e8a87fbadc07f6fa2d 100644 (file)
--- a/gdb.cc
+++ b/gdb.cc
@@ -79,7 +79,6 @@
 
 #define DBG(a,b)               if ((GDB_DEBUG & (a)) && (b))
 
-#define ELEMENTS(a) a->rte_waypt_ct()
 #define NOT_EMPTY(a) (a && *a)
 
 void
@@ -1404,7 +1403,7 @@ GdbFormat::write_route(const route_head* rte, const QString& rte_name)
   route_compute_bounds(rte, &bounds);
   route_write_bounds(&bounds);
 
-  int points = ELEMENTS(rte);
+  int points = rte->rte_waypt_ct();
   FWRITE_i32(points);
 
   int index = 0;
@@ -1513,7 +1512,7 @@ GdbFormat::write_route(const route_head* rte, const QString& rte_name)
 void
 GdbFormat::write_track(const route_head* trk, const QString& trk_name)
 {
-  int points = ELEMENTS(trk);
+  int points = trk->rte_waypt_ct();
 
   FWRITE_CSTR(trk_name);
   FWRITE_C(0);
@@ -1665,7 +1664,7 @@ GdbFormat::write_waypoint_cb(const Waypoint* refpt)
 void
 GdbFormat::write_route_cb(const route_head* rte)
 {
-  if (ELEMENTS(rte) <= 0) {
+  if (rte->rte_waypt_empty()) {
     return;
   }
 
@@ -1687,7 +1686,7 @@ GdbFormat::write_route_cb(const route_head* rte)
 void
 GdbFormat::write_track_cb(const route_head* trk)
 {
-  if (ELEMENTS(trk) <= 0) {
+  if (trk->rte_waypt_empty()) {
     return;
   }
 
diff --git a/gtm.cc b/gtm.cc
index 9460737d9b0c15009c2269c85b276f34a49b4b5d..d2bf5fbfebafeecb0262555cf5f644a0aed06b0d 100644 (file)
--- a/gtm.cc
+++ b/gtm.cc
@@ -425,7 +425,7 @@ gtm_rd_deinit()
 
 static void count_track_styles(const route_head* rte)
 {
-  if (rte->rte_waypt_ct() > 0) {
+  if (!rte->rte_waypt_empty()) {
     ts_count++;
   }
 }
@@ -679,7 +679,7 @@ static void write_trk_waypt(const Waypoint* wpt)
 
 static void write_trk_style(const route_head* trk)
 {
-  if (trk->rte_waypt_ct() > 0) {
+  if (!trk->rte_waypt_empty()) {
     fwrite_string(file_out, trk->rte_name);
     fwrite_byte(file_out, 1);
     fwrite_long(file_out, 0);
index 6f80e4af5120f32b8f7685a4610ec4e12fe374af..cdf807370e2971c00d90d8fadc5423691dcf4ba0 100644 (file)
@@ -686,7 +686,7 @@ HumminbirdHTFormat::humminbird_track_head(const route_head* trk)
 
   trk_head = nullptr;
   last_time = 0;
-  if (trk->rte_waypt_ct() > 0) {
+  if (!trk->rte_waypt_empty()) {
     trk_head = (humminbird_trk_header_t*) xcalloc(1, sizeof(humminbird_trk_header_t));
     trk_points = (humminbird_trk_point_t*) xcalloc(max_points, sizeof(humminbird_trk_point_t));
 
@@ -817,7 +817,7 @@ void
 HumminbirdFormat::humminbird_rte_head(const route_head* rte)
 {
   humrte = nullptr;
-  if (rte->rte_waypt_ct() > 0) {
+  if (!rte->rte_waypt_empty()) {
     humrte = (humminbird_rte_t*) xcalloc(1, sizeof(*humrte));
   }
 }
diff --git a/kml.cc b/kml.cc
index 978b88071b27098765f8f5f1adcf7f16e8e8c542..3a1b71a54d088aecba0967b6aeda7bcaf7c66675 100644 (file)
--- a/kml.cc
+++ b/kml.cc
@@ -242,7 +242,7 @@ void KmlFormat::trk_coord(xg_string args, const QXmlStreamAttributes* /*attrs*/)
   if (wpt_timespan_begin.isValid() && wpt_timespan_end.isValid()) {
 
     // If there are some Waypoints, then distribute the TimeSpan to all Waypoints
-    if (trk_head->rte_waypt_ct() > 0) {
+    if (!trk_head->rte_waypt_empty()) {
       qint64 timespan_ms = wpt_timespan_begin.msecsTo(wpt_timespan_end);
       if (trk_head->rte_waypt_ct() < 2) {
         fatal(MYNAME ": attempt to interpolate TimeSpan with too few points.");
@@ -656,7 +656,7 @@ void KmlFormat::kml_output_header(const route_head* header, const computed_trkda
   writer->writeOptionalTextElement(QStringLiteral("name"), header->rte_name);
   kml_output_trkdescription(header, td);
 
-  if (export_points && header->rte_waypt_ct() > 0) {
+  if (export_points && !header->rte_waypt_empty()) {
     // Put the points in a subfolder
     writer->writeStartElement(QStringLiteral("Folder"));
     writer->writeTextElement(QStringLiteral("name"), QStringLiteral("Points"));
@@ -874,12 +874,12 @@ void KmlFormat::kml_output_point(const Waypoint* waypointp, kml_point_type pt_ty
 void KmlFormat::kml_output_tailer(const route_head* header)
 {
 
-  if (export_points && header->rte_waypt_ct() > 0) {
+  if (export_points && !header->rte_waypt_empty()) {
     writer->writeEndElement(); // Close Folder tag
   }
 
   // Add a linestring for this track?
-  if (export_lines && header->rte_waypt_ct() > 0) {
+  if (export_lines && !header->rte_waypt_empty()) {
     bool needs_multigeometry = false;
 
     foreach (const Waypoint* tpt, header->waypoint_list) {
@@ -1441,7 +1441,7 @@ void KmlFormat::kml_waypt_pr(const Waypoint* waypointp) const
 void KmlFormat::kml_track_hdr(const route_head* header) const
 {
   computed_trkdata td = track_recompute(header);
-  if (header->rte_waypt_ct() > 0 && (export_lines || export_points)) {
+  if (!header->rte_waypt_empty() && (export_lines || export_points)) {
     kml_output_header(header, &td);
   }
 }
@@ -1453,7 +1453,7 @@ void KmlFormat::kml_track_disp(const Waypoint* waypointp) const
 
 void KmlFormat::kml_track_tlr(const route_head* header)
 {
-  if (header->rte_waypt_ct() > 0 && (export_lines || export_points)) {
+  if (!header->rte_waypt_empty() && (export_lines || export_points)) {
     kml_output_tailer(header);
   }
 }
diff --git a/osm.cc b/osm.cc
index 5e3691d0e6a0321025b09e5c4a7941347bbc60e9..91365ef95f5410037c350bb11f0684f3fa407504 100644 (file)
--- a/osm.cc
+++ b/osm.cc
@@ -780,7 +780,7 @@ OsmFormat::osm_waypt_disp(const Waypoint* waypoint)
 void
 OsmFormat::osm_rte_disp_head(const route_head* route)
 {
-  skip_rte = route->rte_waypt_ct() <= 0;
+  skip_rte = route->rte_waypt_empty();
 
   if (skip_rte) {
     return;
diff --git a/ozi.cc b/ozi.cc
index 83d5e3a616bcb13726e60f4024ed0b7b974089aa..14473ac8a14b3210b9b83ecc5c8ef76f51ee131d 100644 (file)
--- a/ozi.cc
+++ b/ozi.cc
@@ -608,7 +608,7 @@ ozi_parse_track(int field, const QString& str, Waypoint* wpt_tmp, char* trk_name
     break;
   case 2:
     /* new track flag */
-    if ((str.toInt() == 1) && (trk_head->rte_waypt_ct() > 0)) {
+    if ((str.toInt() == 1) && !trk_head->rte_waypt_empty()) {
       trk_head = new route_head;
       track_add_head(trk_head);
       if (trk_name) {
index 23ccd3381e201f561ae6fdd66ee48ea27fb53d8f..4d2d0695d9ec78f242066c680848e6066dc8ffec 100644 (file)
@@ -124,7 +124,7 @@ void PositionFilter::position_runqueue(WaypointList* waypt_list, int qtype)
 
 void PositionFilter::position_process_any_route(const route_head* rh, int type)
 {
-  if (rh->rte_waypt_ct() != 0) {
+  if (!rh->rte_waypt_empty()) {
     cur_rte = const_cast<route_head*>(rh);
     position_runqueue(&cur_rte->waypoint_list, type);
     cur_rte = nullptr;
index 5de2464467a672482acf3255a5292e52bfad41aa..b966a93554888b07d34f291eba1c9142ce1506d7 100644 (file)
@@ -183,7 +183,7 @@ QDateTime TrackFilter::trackfilter_get_last_time(const route_head* track)
 
 void TrackFilter::trackfilter_fill_track_list_cb(const route_head* track)      /* callback for track_disp_all */
 {
-  if (track->rte_waypt_ct() == 0) {
+  if (track->rte_waypt_empty()) {
     track_del_head(const_cast<route_head*>(track));
     return;
   }
@@ -272,7 +272,7 @@ void TrackFilter::trackfilter_pack_init_rte_name(route_head* track, const gpsbab
     // Uggh.  strftime format exposed to user.
 
     gpsbabel::DateTime dt;
-    if (track->rte_waypt_ct() == 0) {
+    if (track->rte_waypt_empty()) {
       dt = default_time;
     } else {
       auto* wpt = track->waypoint_list.front();
@@ -392,7 +392,7 @@ void TrackFilter::trackfilter_merge()
       }
     }
 
-    if (master->rte_waypt_ct() == 0) {
+    if (master->rte_waypt_empty()) {
       track_del_head(master);
       track_list.clear();
     }
@@ -733,7 +733,7 @@ void TrackFilter::trackfilter_range()
       }
     }
 
-    if (track->rte_waypt_ct() == 0) {
+    if (track->rte_waypt_empty()) {
       track_del_head(track);
       it = track_list.erase(it);
     } else {